From fe5a875efde0c14414acc0f9cf15d487accd7c50 Mon Sep 17 00:00:00 2001 From: Hunter Praska Date: Tue, 6 Jun 2017 19:24:00 -0500 Subject: [PATCH] Add test for local gitconf --- src/cargo/ops/cargo_new.rs | 2 +- tests/new.rs | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 1e92aa5c7..53bc1a431 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -517,7 +517,7 @@ fn get_environment_variable(variables: &[&str] ) -> Option{ fn discover_author() -> CargoResult<(String, Option)> { let cwd = env::current_dir()?; let git_config = if let Ok(repo) = GitRepository::discover(&cwd) { - repo.config().ok() + repo.config().ok().or_else(|| GitConfig::open_default().ok()) } else { GitConfig::open_default().ok() }; diff --git a/tests/new.rs b/tests/new.rs index 0312d7795..bceda0937 100644 --- a/tests/new.rs +++ b/tests/new.rs @@ -281,6 +281,29 @@ fn finds_author_git() { assert!(contents.contains(r#"authors = ["bar "]"#)); } +#[test] +fn finds_local_author_git() { + process("git").args(&["init"]) + .exec().unwrap(); + process("git").args(&["config", "--global", "user.name", "foo"]) + .exec().unwrap(); + process("git").args(&["config", "--global", "user.email", "foo@bar"]) + .exec().unwrap(); + + // Set local git user config + process("git").args(&["config", "user.name", "bar"]) + .exec().unwrap(); + process("git").args(&["config", "user.email", "baz"]) + .exec().unwrap(); + assert_that(cargo_process("init").env("USER", "foo"), + execs().with_status(0)); + + let toml = paths::root().join("Cargo.toml"); + let mut contents = String::new(); + File::open(&toml).unwrap().read_to_string(&mut contents).unwrap(); + assert!(contents.contains(r#"authors = ["bar "]"#)); +} + #[test] fn finds_git_email() { let td = TempDir::new("cargo").unwrap(); -- 2.30.2